﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace zlh.Adminyemian
{
    public partial class adminzhusu : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["color"] == "1")
            {
                Page.Theme = "1";

            }
            else if (Session["color"] == "2")
            {
                Page.Theme = "2";
            }
            else
            {
                Page.Theme = "3";
            }
        }

        protected void aBtnread_Click(object sender, EventArgs e)
        {
            string strSql = "SELECT   CourseId, CourseName, Coursexuefen, TeaId FROM      Course WHERE   (CourseName = @CourseName)";
            SqlParameter[] pms = new SqlParameter[1];
            pms[0] = new SqlParameter("@CourseName", this.TextBox1.Text);
            SqlDataReader dr = SqlHelper.ExecuteReader(strSql, pms);
            if (dr.Read())
            {
                this.TextBox1.Text = dr["CourseName"].ToString();
                this.TextBox2.Text = dr["CourseId"].ToString();
                this.TextBox3.Text = dr["Coursexuefen"].ToString();
                this.TextBox4.Text = dr["TeaId"].ToString();
                //this.TextBox5.Text = dr["College"].ToString();
                

            }
            dr.Close();//关闭
        }

        protected void Adminupdapt_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder(1024);
            sb.Append("UPDATE  Course ");
            sb.Append("SET        CourseId = @CourseId,CourseName = @CourseName, Coursexuefen = @Coursexuefen, TeaId = @TeaId");
            sb.Append("WHERE   (CourseId = @CourseId) ");

            SqlParameter[] pms = new SqlParameter[4];
            pms[0] = new SqlParameter("@CourseName", this.TextBox1.Text);
            pms[1] = new SqlParameter("@CourseId", this.TextBox2.Text);
            pms[2] = new SqlParameter("@Coursexuefen", this.TextBox3.Text);
            pms[3] = new SqlParameter("@TeaId", this.TextBox4.Text);
            

            int intResult = SqlHelper.ExecuteNonQuery(sb.ToString(), pms);
            this.lblInfo.Text = (intResult < 1) ? "更新失败！" : "更新" + intResult.ToString() + "条记录！";
        }

        protected void Admindelete_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder(1024);
            sb.Append("DELETE FROM Course ");
            sb.Append("WHERE   (CourseId = @CourseId) ");

            SqlParameter[] pms = new SqlParameter[8];
            pms[0] = new SqlParameter("@CourseName", this.TextBox1.Text);
            pms[1] = new SqlParameter("@CourseId", this.TextBox2.Text);
            pms[2] = new SqlParameter("@Coursexuefen", this.TextBox3.Text);
            pms[3] = new SqlParameter("@TeaId", this.TextBox4.Text);

            int intResult = (int)SqlHelper.ExecuteNonQuery(sb.ToString(), pms);
            this.lblInfo.Text = (intResult < 1) ? "删除失败！" : "删除" + intResult.ToString() + "条记录！";
        }

        protected void TextBox4_TextChanged(object sender, EventArgs e)
        {

        }

        protected void Adminadd_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder(1024);
            sb.Append("INSERT INTO Course ");
            sb.Append("                (CourseId, CourseName, Coursexuefen, TeaId) ");
            sb.Append("VALUES   (@CourseId, @CourseName, @Coursexuefen, @TeaId ) ");

            SqlParameter[] pms = new SqlParameter[4];
            pms[0] = new SqlParameter("@CourseName", this.TextBox1.Text);
            pms[1] = new SqlParameter("@CourseId", this.TextBox2.Text);
            pms[2] = new SqlParameter("@Coursexuefen", this.TextBox3.Text);
            pms[3] = new SqlParameter("@TeaId", this.TextBox4.Text);


            int intResult = (int)SqlHelper.ExecuteNonQuery(sb.ToString(), pms);
            this.lblInfo.Text = (intResult < 1) ? "新增失败！" : "新增" + intResult.ToString() + "条记录！";
        }
    }
}